package rge.orumus.encdb;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

@Root
public class OnlineCredentialsRecordData extends RecordData {

	@Element
	public String site;
	@Element
	public String userName;
	@Element
	public String password;
	@Element
	public String email;
	@Element
	public String secretAnswer;
	
	public OnlineCredentialsRecordData() {
		ClearFields();
	}
	
	public OnlineCredentialsRecordData(byte[] encryptedData) {
		super(encryptedData);
	}

	@Override
	public void ClearFields() {
		super.ClearFields();
		site = "";
		userName = "";
		password = "";
		email = "";
		secretAnswer = "";
	}

	@Override
	protected void SetFieldsFrom(RecordData rD){
		super.SetFieldsFrom(rD);
		OnlineCredentialsRecordData rec = (OnlineCredentialsRecordData) rD;
		this.site = rec.site;
		this.userName = rec.userName;
		this.password = rec.password;
		this.email = rec.email;
		this.secretAnswer = rec.secretAnswer;
	}
	
	@Override
	public void SetFieldsFromXml(String xmlString) {
		
		Serializer serializer = new Persister();
		OnlineCredentialsRecordData rec = null;
		
		try {
			rec = serializer.read(OnlineCredentialsRecordData.class, xmlString);
		} catch (Exception e) {
			rec = null;
		}
		
		if(null != rec){
			SetFieldsFrom(rec);
		}
	}

}
